from django import forms
from django.core.exceptions import ValidationError

from user.models import User


class LoginForm(forms.Form):
    username = forms.CharField(label="用户名", max_length=20,
                               widget=forms.TextInput(attrs={'class': 'name_input', "placeholder": '请输入用户名'}))
    password = forms.CharField(label="密码", max_length=12,
                               widget=forms.PasswordInput(attrs={'class': 'pass_input', "placeholder": '请输入密码'}))
    check_me = forms.BooleanField()


class RegisterForm(forms.Form):
    username = forms.CharField(label='用户名', max_length=20, widget=forms.TextInput())
    password = forms.CharField(label='密码', max_length=12, widget=forms.PasswordInput())
    password2 = forms.CharField(label='确认密码', max_length=12, widget=forms.PasswordInput())
    email = forms.CharField(label='邮箱', max_length=20)
    check_me = forms.BooleanField()

    def clean_password(self):
        print(self.data)
        if self.data["password"] != self.data["password2"]:
            raise ValidationError("两次密码不一致")

